package com.cyl.h5.controller;

import com.cyl.h5.service.H5MemberAddressService;
import com.cyl.manager.ums.domain.form.MemberAddressForm;
import com.cyl.manager.ums.domain.vo.MemberAddressVO;
import com.ruoyi.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "用户收获地址接口")
@RestController
@RequestMapping("/app/member/address")
public class   H5MemberAddressController {

  @Autowired
  private H5MemberAddressService h5MemberAddressService;

  @ApiOperation("查询用户收获地址列表")
  @GetMapping("/list")
  public R<List<MemberAddressVO>> getList(){
    return R.ok(h5MemberAddressService.selectList());
  }

  @ApiOperation("查询用户默认收获地址")
  @GetMapping("/default")
  public R<MemberAddressVO> getDefault(){
    return R.ok(h5MemberAddressService.getDefault());
  }

  @ApiOperation("添加地址")
  @PostMapping("/create")
  public R<Integer> create(@RequestBody MemberAddressForm memberAddressForm){
    return R.ok(h5MemberAddressService.insert(memberAddressForm));
  }

  @ApiOperation("更新地址")
  @PutMapping("/update")
  public R<Integer> update(@RequestBody MemberAddressForm memberAddressForm){
    return R.ok(h5MemberAddressService.update(memberAddressForm));
  }

  @ApiOperation("获取地址详细信息")
  @GetMapping("/{id}")
  public R<MemberAddressVO> getInfo(@PathVariable Long id){
    return R.ok(h5MemberAddressService.selectById(id));
  }

  @ApiOperation("删除地址")
  @DeleteMapping("/{id}")
  public R<Integer> remove(@PathVariable Long id) {
    return R.ok(h5MemberAddressService.deleteById(id));
  }
}
